<!DOCTYPE html>
<html lang="zh">

<head>

    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>页面</title>
    <script src="https://pinzafile.oss-cn-shanghai.aliyuncs.com/vue-element/loading.js"></script>
    <link href="https://pinzafile.oss-cn-shanghai.aliyuncs.com/vue-element/lib/theme-chalk/index.css" rel="stylesheet">

</head>

<style>
    .spacing {
        height: 50px;
    }
</style>
<body>
<div id="app">
    <el-container v-loading="loading">
        <el-main>
            <el-header>
                <el-breadcrumb separator-class="el-icon-arrow-right">
                    <el-breadcrumb-item :to="{ path: '/' }">PM订单管理</el-breadcrumb-item>
                    <el-breadcrumb-item>订单列表</el-breadcrumb-item>
                </el-breadcrumb>
            </el-header>
            <el-row>
                <el-col :xs="8" :sm="8" :md="4" :lg="2" :xl="2" class="spacing">
                    <el-button type="primary" icon="el-icon-refresh" @click="refresh">刷新</el-button>
                </el-col>
                <el-col :xs="14" :sm="14" :md="8" :lg="8" :xl="8" class="spacing">
                    <el-input placeholder="请输入内容" @keyup.enter.native="enterSearch" v-model="keySearch"
                              style="width: 100%">
                        <el-button slot="append" icon="el-icon-search" @click=search></el-button>
                    </el-input>
                </el-col>
            </el-row>
            <el-table v-loading="tableLoading" :data="tableData" stripe border style="width:100%" highlight-current-row
                      size="mini"
                      tooltip-effect="dark" height="calc(100vh - 240px)">
                <el-table-column label="序号" align="center" width="50px">
                    <template scope="scope"><span>{{scope.$index+(currentPage - 1) * pageSize + 1}}</span></template>
                </el-table-column>
                　　
                <el-table-column prop="order_code" label="订单编号" align="center" :show-overflow-tooltip=true>
                    　　
                </el-table-column>
                <el-table-column prop="project_name" label="项目名称" align="center" :show-overflow-tooltip=true>
                    　　
                </el-table-column>
                <el-table-column prop="buyer_name" label="客户联系人" align="center" :show-overflow-tooltip=true>
                    　　
                </el-table-column>
                <el-table-column prop="organizationName" label="客户名称" align="center" :show-overflow-tooltip=true>
                    　　
                </el-table-column>
                　　
                <el-table-column prop="order_date" label="订单日期" align="center" :show-overflow-tooltip=true>
                    　　
                </el-table-column>
                <el-table-column prop="order_amount" label="订单金额（元）" align="center" :show-overflow-tooltip=true>
                    　　
                </el-table-column>
                <el-table-column prop="workflow_status" label="流程状态" align="center" :formatter="workflowStatus"
                                 :show-overflow-tooltip=true>
                    　　
                </el-table-column>
                <el-table-column prop="order_auditor" label="审核状态" align="center" :formatter="auditor"
                                 :show-overflow-tooltip=true>
                    　　
                </el-table-column>
                <el-table-column prop="order_status" label="订单状态" align="center" :formatter="formatStatus"
                                 :show-overflow-tooltip=true>
                    　　
                </el-table-column>
                　
                　　
                <el-table-column label="操作" align="center" min-width="140" fixed="right">
                    　　　　
                    <template slot-scope="scope">
                    <#--　　　　　<template v-for="item in button">-->
                    <#--<el-button type="text" @click="item.fn(scope.row.id)">{{item.name}}</el-button>-->
                    <#--</template>-->
                        　　　　　
                        <el-button type="text"
                                   @click="detail(scope.row)">
                            查看
                        </el-button>
                        <el-button type="text" v-if="scope.row.order_auditor=='false'"
                                   @click="refreshOrder(scope.row)">
                            刷新
                        </el-button>
                        <el-button type="text" v-if="scope.row.order_status==99 && scope.row.order_auditor=='true'"
                                   @click="submit(scope.row)">
                            导入
                        </el-button>
                        <el-button type="text" v-if="scope.row.order_status==99 && scope.row.order_auditor=='true'"
                                   @click="openDialog(scope.row)">
                            通知
                        </el-button>
                        <el-button type="text" v-if="scope.row.order_status==99 && scope.row.order_auditor=='true'"
                                   @click="cancel(scope.row)">
                            作废
                        </el-button>
                    </template>
                    　　
                </el-table-column>
            </el-table>
        </el-main>
        <el-footer>
            <el-row>
                <el-col>
                    <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                                   :page-sizes="[100, 500, 1000]" :page-size="pageSize"
                                   layout="total, sizes, prev, pager, next, jumper"
                                   :total="totalRecords">
                    </el-pagination>
                </el-col>
            </el-row>
        </el-footer>
    </el-container>
    <el-dialog title="提示" :visible.sync="dialogFormVisible" @close="closeDialog">
        <el-form>
            <el-form-item label="备注">
                <el-input type="textarea" v-model="key"></el-input>
            </el-form-item>
        </el-form>
        <div slot="footer">
            <el-button @click="closeDialog">取 消</el-button>
            <el-button type="primary" @click="refuse">确 定</el-button>
        </div>
    </el-dialog>
</div>

<script src="https://pinzafile.oss-cn-shanghai.aliyuncs.com/vue-element/dist/vue.js"></script>
<script src="https://pinzafile.oss-cn-shanghai.aliyuncs.com/vue-element/lib/index.js"></script>
<script src="https://pinzafile.oss-cn-shanghai.aliyuncs.com/publiccss/assets/global/plugins/jquery.min.js"
        type="text/javascript"></script>
<script>
    new Vue({
        el: '#app',
        data() {
            return {
                tableLoading: false,
                loading: false,
                dialogFormVisible: false,
                keySearch: '',
                tableData: [],
                currentPage: 1, //当前页
                pageSize: 100, //每页总数
                totalRecords: 0, //总条数
                reason: {},
                key: '',

            <#--button:'${operaButton}',-->
            };
        },

        methods: {
            //获取订单最新流程状态
            refreshOrder: function (row) {
                this.loading = true;
                $.ajax({
                    url: '/pmOrder/refreshPMOrderStatus.json?order_id=' + row.order_id,
                    type: 'get',
                    // async: false,
                    dataType: 'json',
                    success: (result) => {
                        this.loading = false;
                        console.log(result);
                        if (result.ret) {
                            this.$message({
                                message: '操作成功',
                                type: 'success'
                            });
                            this.ajaxFunction();
                        } else {
                            this.$message({
                                message: "请求超时，请稍后重试",
                                type: 'error'
                            });
                        }
                    }
                });
            },
            auditor: function (row, column) {
                return row.order_auditor == 'true' ? '已审核' : row.order_auditor == 'false' ? '未审核' : '未知';
            },
            //状态转换
            formatStatus: function (row, column) {
                return row.order_status == 11 ? '已导入' : row.order_status == 99 ? '未导入' : '未知';
            },
            //状态转换
            workflowStatus: function (row, column) {
                return row.workflow_status == 'COMPLETED' ? '已结束' : row.order_status == 'WAITSIGN' ? '待审批' : row.order_status == 'PENDING' ? '审批中' : row.order_status == 'BACK' ? '已驳回' : '草稿';
            },
            openDialog(row) {
                this.dialogFormVisible = true;
                this.reason = row;
            },
            closeDialog() {
                this.dialogFormVisible = false;
                this.reason = {};
                this.key = '';
            },
            refuse() {
                if (this.key == '') {
                    this.$message({
                        message: "拒绝理由不可以为空",
                        type: 'error'
                    });
                    return false;
                }
                this.loading = true;
                this.reason.reason = this.key;
                $.ajax({
                    url: '/pmOrder/refuse.json',
                    type: 'post',
                    data: {reason: JSON.stringify(this.reason)},
                    // async: false,
                    dataType: 'json',
                    success: (result) => {
                        this.dialogFormVisible = false;
                        this.loading = false;
                        if (result.ret) {
                            this.$message({
                                message: '提交成功',
                                type: 'success'
                            });
                            this.ajaxFunction();
                        } else {
                            this.$message({
                                message: "请求失败，请稍后重试",
                                type: 'error'
                            });
                        }
                    }
                });
            },
            cancel(row) {
                this.$confirm('此订单一旦作废不可撤回，是否确认?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.loading = true;
                    //声明要发送的参数
                    var err = "系统异常！";
                    $.ajax({
                        url: '/pmOrder/update.json?order_id=' + row.order_id,
                        type: 'get',
                        // async: false,
                        dataType: 'json',
                        success: (result) => {
                            this.loading = false;
                            if (result.ret) {
                                this.$message({
                                    message: '操作成功',
                                    type: 'success'
                                });
                                this.ajaxFunction();
                            } else {
                                err = result.msg;
                                this.$message({
                                    message: "操作失败，请稍后重试",
                                    type: 'error'
                                });
                            }
                        }
                    });
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消操作'
                    });
                });
            },
            //回车监听事件获取输入内容
            enterSearch: function (event) {
                this.currentPage = 1;
                this.pageSize = 100;
                this.keySearch = event.target.value;
                this.ajaxFunction()
            },
            search() {
                this.currentPage = 1;
                this.pageSize = 100;
                //声明要发送的参数
                this.ajaxFunction();
            },
            //查看详情
            detail(row) {
                window.location.href = "/pmOrder/detailOrderByPM.page?dataId=" + row.order_id;
            },
            async handleSizeChange(val) {
                this.pageSize = val;
                this.ajaxFunction();
            },
            async handleCurrentChange(val) {
                this.currentPage = val;
                this.ajaxFunction();
            },
            submit(row) {
                this.$confirm('请确认是否导入?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.loading = true;
                    //声明要发送的参数
                    var err = "系统异常！";
                    $.ajax({
                        url: '/pmOrder/submitOrderByPM.json',
                        type: 'post',
                        data: {
                            dataId: row.order_id,
                        },
                        // async: false,
                        dataType: 'json',
                        success: (result) => {
                            this.loading = false;
                            if (result.ret) {
                                this.$message({
                                    message: '操作成功',
                                    type: 'success'
                                });
                                this.ajaxFunction();
                            } else {
                                err = result.msg;
                                this.$message({
                                    message: err,
                                    type: 'error'
                                });
                            }
                        }
                    });
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消操作'
                    });
                });
            },
            ajaxFunction() {
                this.tableLoading = true;
                $.ajax({
                    url: '/pmOrder/list.json',
                    type: 'post',
                    data: {key: this.keySearch, page: this.currentPage, limit: this.pageSize},
                    dataType: 'json',
                    success: (result) => {
                        this.tableLoading = false;
                        if (result.ret) {
                            this.tableData = result.data.list;
                            this.totalRecords = result.data.total;
                        } else {
                            this.$message({
                                message: "请求失败，请稍后重试",
                                type: 'error'
                            });
                        }
                    }
                });
            },
            refresh() {
                this.loading = true;
                //声明要发送的参数
                var err = "系统异常！";
                $.ajax({
                    url: '/pmOrder/getOrderListByPM.json',
                    type: 'get',
                    // async: false,
                    success: (result) => {
                        this.loading = false;
                        if (result.ret) {
                            this.ajaxFunction();
                            this.$message({
                                message: "同步成功",
                                type: 'success'
                            });
                        } else {
                            err = result.msg;
                            this.$message({
                                message: err,
                                type: 'error'
                            });
                        }
                    }
                });
            },
        },
        async mounted() {
            this.ajaxFunction();
        }
    })
</script>
</body>

</html>